<template>
<span class="yxt-flex-between">
  <span style="line-height: 48px;">{{date}}</span>
  <span style="line-height: 48px;">{{week}}</span>
  <span><img :src="`/image/weathers/${wea_img}.png`"/></span>
  <span style="line-height: 48px;">{{tem}} ℃</span>
</span>
</template>

<script>
import {request, service} from "@/api/service";

export default {
  name: "weather",
  data () {
      return {
        wea_img: 'yin',
        tem: '',
        date: '',
        week: ''
      }
    },
    methods: {
      // 参考：http://www.tianqiapi.com/index/doc?version=day
      getWeaAndTem() {
        service({
          method: 'get',
          url: 'https://yiketianqi.com/free/day',
          headers:{},
          params: {
            appid: '18521224', // 账号ID
            appsecret: 'xHHI97m7', // 账号密钥
            unescape:1
          },
        })
          .then((res) => {
            this.date = res.date;
            this.week = res.week;
            this.wea_img = res.wea_img;
            this.tem = res.tem;
          })
          .catch((error) => {
            console.log(error);
          });
      }
    },
    created () {
      this.getWeaAndTem();
    },
}
</script>

<style scoped>

</style>
